<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>职工档案管理系统</title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/font-awesome.min.css">
  <link rel="stylesheet" href="css/ionicons.min.css">
  <link rel="stylesheet" href="css/AdminLTE.min.css">
  <link rel="stylesheet" href="css/kin-blue.min.css">

  <script src="js/jquery.min.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <script src="js/adminlte.min.js"></script>


</head>

<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

  <div class="content-wrapper">
      <h1>职工档案管理</h1><a href="zhiwuList.html">职务管理</a>
      <div class="input-group input-group-sm">
          <label>职工姓名</label>
          <span>
              <input type="text" id="name" >
              <button type="button" onclick="sel()" class="btn btn-info btn-flat">查询</button>
              <a onclick="addWorkers()" class="btn btn-info btn-flat">添加</a>
          </span>
      </div>
      <div class="box">
            <div class="box-header">
            </div>
            <div class="box-body no-padding">
              <table class="table table-striped">
              	<thead>
	              	<tr>
	                  <th>职工编号</th>
	                  <th>姓名</th>
	                  <th>性别</th>
	                  <th>年龄</th>
	                  <th>学历</th>
	                  <th>地址</th>
	                  <th>电话</th>
	                  <th>修改</th>
	                  <th>删除</th>
	                </tr>
	                
              	</thead>
                <tbody id="tbody1">
              	</tbody>
              </table>
            </div>
          </div>
  </div>

  <aside class="control-sidebar control-sidebar-dark">
    <ul class="nav nav-tabs nav-justified control-sidebar-tabs">
      <li class="active"><a href="#control-sidebar-home-tab" data-toggle="tab"><i class="fa fa-home"></i></a></li>
      <li><a href="#control-sidebar-settings-tab" data-toggle="tab"><i class="fa fa-gears"></i></a></li>
    </ul>

  </aside>
  <div class="control-sidebar-bg"></div>
</div>

</body>
</html>
<script type="text/javascript">
$(function(){
	showAll('');
})
function sel(){
	var name = $("#name").val();
	showAll(name);
}
function showAll(name) {
    console.log(name)
	var html = '';
	$.ajax({
        url : "users/listWorkers",
        type : "post",
        data : {
        	"name" : name
        },
        async : false,
        cache : false,
        dataType : "json",
        success : function(obj) {
            obj = obj.data;
        	for(var i=0;i<obj.length;i++){
        		html = html+"<tr>";
        		html = html+"<th>"+obj[i].id+"</th>";
        		html = html+"<th>"+obj[i].name+"</th>";
        		html = html+"<th>"+obj[i].sex+"</th>";
        		html = html+"<th>"+obj[i].age+"</th>";
        		html = html+"<th>"+obj[i].education+"</th>";
        		html = html+"<th>"+obj[i].address+"</th>";
        		html = html+"<th>"+obj[i].phone+"</th>";
        		html = html+"<th><input class='btn btn-outline-primary' type='button' onclick='upd("+obj[i].id+")' value='修改'></th>";
        		html = html+"<th><input class='btn btn-outline-danger' type='button' onclick='del("+obj[i].id+")' value='删除'></th>";
        		html = html+"</tr>";
        	}
        }
    });
	$("#tbody1").html(html);
	
}
function addWorkers(){
    //检查权限
    $.ajax({
        url : "users/addJQWorkers",
        type : "post",
        async : false,
        cache : false,
        dataType : "json",
        success : function(obj) {
            if(obj=='正在访问未授权的资源'){
                alert(obj)
            }else{
                window.location.href='addWorkers.html';
            }
        },error:function (xhr,errorMessage,e){
            console.log(xhr)
            console.log(errorMessage)
            console.log(e)
        }
    })
}
function del(id){
	$.ajax({
        url : "/users/deleteWorkers",
        type : "post",
        data : {
            "id" : id
        },
        async : false,
        cache : false,
        dataType : "json",
        success : function(obj) {
            console.log(obj)
            if(obj=='正在访问未授权的资源'){
                alert(obj)
            }else{
                showAll('');
            }
        }
    });
}

function upd(id){//检查权限
    $.ajax({
        url : "users/updJQWorkers",
        type : "post",
        async : false,
        cache : false,
        dataType : "json",
        success : function(obj) {
            if(obj=='正在访问未授权的资源'){
                alert(obj)
            }else{
                window.location.href='updateWorkers.html?id='+id;
            }
        },error:function (xhr,errorMessage,e){
            console.log(xhr)
            console.log(errorMessage)
            console.log(e)
        }
    })
}
</script>